/*
 * User: ophir
 * Date: Oct 17, 2008
 * Time: 11:30:16 PM
 */
package javax.webbeans;

import java.lang.annotation.Annotation;
import java.lang.reflect.ParameterizedType;

public abstract class AnnotationLiteral<T extends Annotation> implements Annotation {

    protected AnnotationLiteral() {
        if (!(getClass().getSuperclass() == AnnotationLiteral.class)) {
            throw new RuntimeException("Not a direct subclass of AnnotationLiteral");
        }
        if (!(getClass().getGenericSuperclass() instanceof ParameterizedType)) {
            throw new RuntimeException("Missing type parameter in AnnotationLiteral");
        }
    }

    @SuppressWarnings("unchecked")
    public final Class<T> annotationType() {
        ParameterizedType parameterized = (ParameterizedType) getClass().getGenericSuperclass();
        return (Class<T>) parameterized.getActualTypeArguments()[0];
    }
}
